package com.example.gyj.controller;

import com.example.gyj.rabbitmq.MQSender;
import com.example.gyj.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 测试
 * @author Gao
 * @date 2018/11/1
 */
@Controller
@RequestMapping(value = "/test")
public class TestController {

    @Autowired
    private MQSender sender;

    ///控制台打印   -----------send message:hello world!   *********receive message:hello world!
    @RequestMapping(value = "/mq")
    @ResponseBody
    public Result<String> mq() {
        sender.send("hello world!");
        return Result.success("6666666666666");
    }

    //控制台输出  send topic message:hello,world     topic queue2 message:hello,world1
    ///topic queue1 message:hello,world1    topic queue2 message:hello,world2
    @RequestMapping("/mq/topic")
    @ResponseBody
    public Result<String> topic() {
        sender.sendTopic("hello,world");
        return Result.success("hello topic");
    }

    // 控制台输出 -----------send fanout message:hello,fanout
    ///topic queue2 message:hello,fanout     topic queue1 message:hello,fanout
    @RequestMapping("/mq/fanout")
    @ResponseBody
    public Result<String> fanout() {
        sender.sendFanout("hello,fanout");
        return Result.success("hello world");
    }

    /**
     * header 模式
     */
    ///输出结果 send header message:hello,h      接收：-----header queue message:hello,h
    @RequestMapping("/mq/header")
    @ResponseBody
    public Result<String> header() {
        sender.sendHeader("hello,h");
        return Result.success("hello world");
    }
}
